/**
 * Fine Day for Sailing color palette utility
 */

// Color palette definition
const colorPalette = {
  fineDayForSailing: {
    blue: { name: 'Fine-Day-for-Sailing-1', hex: '#01415B', rgb: [1, 65, 91] },
    teal: { name: 'Fine-Day-for-Sailing-2', hex: '#005148', rgb: [0, 80, 72] },
    turquoise: { name: 'Fine-Day-for-Sailing-3', hex: '#019587', rgb: [1, 149, 135] },
    lime: { name: 'Fine-Day-for-Sailing-4', hex: '#A6BC09', rgb: [165, 188, 8] },
    paleGreen: { name: 'Fine-Day-for-Sailing-5', hex: '#CCEA8D', rgb: [204, 233, 140] }
  }
}

// Format a color to different output formats
function formatColor(color, format = 'hex') {
  if (!color) return null
  
  switch (format) {
    case 'hex':
      return color.hex
    case 'rgb':
      return `rgb(${color.rgb.join(', ')})`
    case 'object':
      return color
    default:
      return color.hex
  }
}

// Hook to access the color palette
export function useColors() {
  const getColor = (colorName, format = 'hex') => {
    // Parse the color path (e.g., 'fineDayForSailing.blue')
    const [paletteName, colorKey] = colorName.includes('.') 
      ? colorName.split('.')
      : ['fineDayForSailing', colorName]
    
    const colorPaletteSection = colorPalette[paletteName]
    if (!colorPaletteSection) return null
    
    const color = colorPaletteSection[colorKey]
    if (!color) return null
    
    return formatColor(color, format)
  }
  
  const getPalette = (paletteName = 'fineDayForSailing', format = 'hex') => {
    const palette = colorPalette[paletteName]
    if (!palette) return {}
    
    return Object.entries(palette).reduce((acc, [key, color]) => {
      acc[key] = formatColor(color, format)
      return acc
    }, {})
  }
  
  return {
    getColor,
    getPalette,
    // Expose the full palette for reference
    palette: colorPalette
  }
} 